﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using IDAL;
using System.Data.SqlClient;
using System.Data;
using Newtonsoft.Json;
namespace DAL
{
   public class Sell_DAL:ISell
   {
       SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=MengQiqidb;Integrated Security=True");//数据库连接对象

        public int Add(Sell_tb model)
        {
            throw new NotImplementedException();
        }

        public int Upt(Sell_tb model)
        {
            throw new NotImplementedException();
        }

        public int Del(object id)
        {
            throw new NotImplementedException();
        }
        #region 获取销售基本信息
        public List<Sell_tb> GetData()
        {
            SqlCommand cmd = new SqlCommand("p_getSellData", conn);//创建命令对象
            cmd.CommandType = CommandType.StoredProcedure;//声明存储过程
            try//异常处理机制
            {
                conn.Open();//打开数据库
                DataTable dt = new DataTable();
                SqlDataAdapter adapter = new SqlDataAdapter();
                adapter.Fill(dt);//填充数据
                List<Sell_tb> list = JsonConvert.DeserializeObject<List<Sell_tb>>(JsonConvert.SerializeObject(dt));
                return list;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();//关闭数据库
                conn.Dispose();//释放内存
            }
        }
        #endregion
   }
}
